<html>
<head><meta charset="utf-8"><title>Moving AST information out of the HIR tree · t-compiler/wg-incr-comp · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/index.html">t-compiler/wg-incr-comp</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html">Moving AST information out of the HIR tree</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218959602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/218959602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#218959602">(Dec 05 2020 at 23:49)</a>:</h4>
<p>Hi <span class="user-group-mention" data-user-group-id="3282">@wg-incr-comp</span> </p>
<p>Earlier this year, I submitted MCP <a href="https://github.com/rust-lang/compiler-team/issues/294">https://github.com/rust-lang/compiler-team/issues/294</a>, which proposes removing <code>Span</code> information out of the HIR tree, and into a side table. This turns to be a larger change than initially thought, so I need some design help.</p>
<p>I submitted <a href="https://github.com/rust-lang/rust/issues/79519">#79519</a> last week, doing essentially the same thing with <code>[Attribute]</code> leaves. It is an opportunity to evaluate the basic idea on a smaller problem. It shows a reduction in the HIR invalidation for incremental tests. Perf is pending.</p>
<p>Completing the initial plan of removing <code>Span</code>s additionally requires to remove <code>Ident</code>s from the HIR. However, this is a much more risky operation, since <code>Ident</code>s are used for hygienic comparisons and pretty-printing. One possibility would be to introduce a new <code>hir::Ident</code> struct with carefully chosen content. What do you recommend?</p>
<p>Last point: it is not possible to measure perf gains before having completely removed <code>Ident</code> and <code>Span</code> from HIR, so design iterations discussions are difficult.</p>



<a name="219415346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/219415346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#219415346">(Dec 09 2020 at 23:37)</a>:</h4>
<p>This is now also somewhat relevant for rust-analyzer, which currently mostly ignores spans and associated data like hygiene, <code>$crate</code>, and the edition.</p>
<p>The fact that we ignore <code>$crate</code> (and instead implement resolution of <code>$crate</code> paths with an approximation) is now causing incorrect diagnostics that are hard/impossible to fix without reimplementing this properly.</p>
<p>Maybe it would make sense to try out different approaches there? The code base is quite a lot easier to work with than rustc.</p>



<a name="219914576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/219914576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#219914576">(Dec 14 2020 at 22:58)</a>:</h4>
<p>If I understand correctly, the resolution in rustc runs on the AST, not on the HIR. The HIR is already resolved, and is dedicated to typechecking and other checks and lints, before turning into MIR.</p>



<a name="219915101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/219915101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#219915101">(Dec 14 2020 at 23:04)</a>:</h4>
<p>The only exception is the distinction between hygienic vs non-hygienic names. I need to wrap my head around this before I touch that code.</p>



<a name="219915360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/219915360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#219915360">(Dec 14 2020 at 23:07)</a>:</h4>
<p>I should be able to remove the position part of the Span (ie where in the file), but I will need to preserve expansion info for idents.</p>



<a name="219915390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/219915390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#219915390">(Dec 14 2020 at 23:07)</a>:</h4>
<p>Does that seem correct ?</p>



<a name="220018787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220018787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220018787">(Dec 15 2020 at 18:09)</a>:</h4>
<p>Does that seem correct ?</p>



<a name="220023167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220023167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220023167">(Dec 15 2020 at 18:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree/near/219914576">said</a>:</p>
<blockquote>
<p>If I understand correctly, the resolution in rustc runs on the AST, not on the HIR. The HIR is already resolved, and is dedicated to typechecking and other checks and lints, before turning into MIR.</p>
</blockquote>
<p>This is definitely correct</p>



<a name="220023259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220023259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220023259">(Dec 15 2020 at 18:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree/near/219915101">said</a>:</p>
<blockquote>
<p>The only exception is the distinction between hygienic vs non-hygienic names. I need to wrap my head around this before I touch that code.</p>
</blockquote>
<p>This part I don't know about. I don't think I've ever touched expansion/proc_macros in the compiler.</p>



<a name="220023363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220023363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220023363">(Dec 15 2020 at 18:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree/near/219915360">said</a>:</p>
<blockquote>
<p>I should be able to remove the position part of the Span (ie where in the file), but I will need to preserve expansion info for idents.</p>
</blockquote>
<p>This _sounds_ correct to me but as I said, I don't know the details in that part of the compiler.</p>



<a name="220023944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220023944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220023944">(Dec 15 2020 at 18:47)</a>:</h4>
<p>This reminds me of <a href="https://github.com/rust-lang/rust/issues/54725">#54725</a> which tracks some unstable <code>proc_macro</code> apis that give access to span information. We may still need to get access to span information for a idents somehow to support these apis.</p>



<a name="220026719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220026719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220026719">(Dec 15 2020 at 19:08)</a>:</h4>
<p>(I did not mean to double post, sorry for the noise.)<br>
Thanks anyway for the answer :)</p>



<a name="220026841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220026841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220026841">(Dec 15 2020 at 19:09)</a>:</h4>
<p>No worries! Sorry I couldn't answer more definitively :)</p>



<a name="220032557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/Moving%20AST%20information%20out%20of%20the%20HIR%20tree/near/220032557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree.html#220032557">(Dec 15 2020 at 19:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20AST.20information.20out.20of.20the.20HIR.20tree/near/219914576">said</a>:</p>
<blockquote>
<p>If I understand correctly, the resolution in rustc runs on the AST, not on the HIR. The HIR is already resolved, and is dedicated to typechecking and other checks and lints, before turning into MIR.</p>
</blockquote>
<p>Module-relative name resolution is performed on AST, type-relative name resolution is performed on HIR, both use same span-based approach to hygiene.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>